package com.guosifan.controller;

import com.guosifan.entity.User;
import com.guosifan.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserRepository userRepository;

    @GetMapping("/findAll")
    public List<User> findAll(@RequestParam int index,@RequestParam int limit){
        return userRepository.findAll(index,limit);
    }

    @GetMapping("/count")
    public int count(){
        return userRepository.count();
    }

    @PostMapping("/save")
    public int save(@RequestBody User user){
        return userRepository.save(user);
    }

    @GetMapping("/deleteById/{id}")
    public int deleteById(@PathVariable("id") int id){
        return userRepository.deleteById(id);
    }


}
